<template>
  <div>
    <el-row
      type="flex"
      align="middle"
    >
      <el-col :span="22">工单项目列表</el-col>
    </el-row>
    <el-divider content-position="center"></el-divider>
    <el-row>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
        <template #allNum>
          <div class="tabelAomut">
            <div>
              项目总金额：<span>￥{{ projectSum }}</span>
            </div>
            <div>
              项目优惠金额：<span>￥{{ projectSum - totalAmount }}</span>
            </div>
            <div>
              项目折后总金额：<span>￥{{ totalAmount }}</span>
            </div>
          </div>
        </template>
      </data-table>
    </el-row>
  </div>
</template>

<script>
import baseMixin from '@/mixins/base'

export default {
  name: 'carInfo',
  components: {},
  props: ['workOrderId', 'workOrderType'], // workOrderType 工单类型 1快速单
  mixins: [
    baseMixin({
      // findData: rapidProjectList,
      dataName: ['content', 'totalRecords'],
      idName: 'id',
    }),
  ],
  computed: {
    totalAmount () {
      let sum = 0
      this.tableData.forEach((item) => {
        //计算
        sum += Number(item.shouldAmount)
      })
      return sum
    },
    projectSum () {
      let sum = 0
      this.tableData.forEach((item) => {
        //计算
        // sum += Number(item.projectHours * Number(item.projectPrice || item.amount))
        sum += Number(item.projectPrice || item.amount)
      })

      return sum
    },
  },
  data () {
    return {
      tableColumnAttributes: [
        { name: '项目名', value: 'projectName', type: 'text' },
        { name: '项目工时', value: 'projectHours', type: 'text' },
        { name: '项目类型', value: 'projectType', type: 'text' },
        { name: '工时费', value: 'amount', type: 'text' },
        { name: '折扣', value: 'discount', type: 'text' },
        { name: '折后金额', value: 'shouldAmount', type: 'text' },
        { name: '状态', value: 'status', type: 'text' },
        { name: '收费类型', value: 'tollType', type: 'text' },
        { name: '作业人员/组', value: 'workUserName', type: 'text' },
      ],
      rules: [],
    }
  },
  async created () {
    this.notQuery = false;
    this.searchOptions[`${this.$parent.getConfig.orderProjectList.queryField}`] = this.workOrderId
    this.setTableData()
  },
  methods: {
    async setTableData () {
      if (!this.notQuery) {
        let fun = this.$parent.getConfig.orderProjectList.query;
        if (fun) {
          let res = await fun(this.searchOptions, this.pageSize, this.currentPage);
          this.totalCount = parseInt(res.data['totalRecords']);
          this.tableData = res.data['content'];
        }
      }
    },
    changeType (item) {
      this.selectedTypeText = item.label
    },
  },
  mounted () { },
}
</script>

<style lang="scss" scoped>

</style>
